package evolution_superclasses;

import java.util.Random;

import misc.Input_Handler;
import misc.not_Legal_Exception;

public abstract class Fitness_Evaluation {
	protected int _methodNr;
	protected Input_Handler _ih;
	protected Random _rand;
	protected boolean _print = false;
	private Phenotype _answer = null;
	
	public Phenotype get_answer() {
		return _answer;
	}

	public void set_answer(Phenotype answer) {
		_answer = answer;
	}

	public Fitness_Evaluation(int nr, boolean print) throws not_Legal_Exception{
		_print = print;
		_methodNr = nr;
		_ih = new Input_Handler();
		_rand = new Random();
		if(nr < 0 || nr > 1)throw new not_Legal_Exception("No such fitness method!");
	}
	
	public double evaluateFitness(Phenotype p) throws not_Legal_Exception{
		double fitness = 0;
		switch (_methodNr) {
			case 0:
				fitness = vectorAverage(p);
				break;
			case 1:
				fitness = distanceFromAnswer(p);
				break;
			default:
				throw new not_Legal_Exception("No such fitness method!");
		}
		return fitness;
	}
	
	protected abstract double vectorAverage(Phenotype p);
	protected abstract double distanceFromAnswer(Phenotype p) throws not_Legal_Exception ;
	
	protected abstract void createRandomSolution(int size);
	protected abstract void createCustomSolution(int size);

}
